home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / FLAME.ZIP / FLAME.PAS < prev   
Pascal/Delphi Source File  |  1993-12-17  |  13KB  |  252 lines

  1. {$G+}
  2.  
  3. program flames;
  4.  
  5. uses crt;
  6.  
  7. {**************************************************************************}
  8. {*                                                                        *}
  9. {*    FLAMES by M.D.Mackey  (C) 1993                                      *}
  10. {*        This code released into the public domain. It may be freely     *}
  11. {*        used, distributed and modified. I would appreciate it if        *}
  12. {*        credit were given, however. If you have any improvements,       *}
  13. {*        find any bugs etc. mail me at mackey@aqueous.ml.csiro.au        *}
  14. {*        with MARK: in the subject header.                               *}
  15. {*                                                                        *}
  16. {**************************************************************************}
  17.  
  18. {**************************************************************************}
  19. {*                                                                        *}
  20. {*  Modified 12-Dec-93: John M. Beck                                      *}
  21. {*                                                                        *}
  22. {*     Restructured and added wave effect by tracing sin path.            *}
  23. {*                                                                        *}
  24. {**************************************************************************}
  25.  
  26. const palette : array [1..768] of byte = (
  27.  
  28.     0,    0,    0,    0,    0,    24,    0,    0,    24,    0,    0,    28,
  29.     0,    0,   32,    0,    0,    32,    0,    0,    36,    0,    0,    40,
  30.     8,    0,   40,   16,    0,    36,   24,    0,    36,   32,    0,    32,
  31.    40,    0,   28,   48,    0,    28,   56,    0,    24,   64,    0,    20,
  32.    72,    0,   20,   80,    0,    16,   88,    0,    16,   96,    0,    12,
  33.   104,    0,    8,  112,    0,     8,  120,    0,     4,  128,    0,     0,
  34.   128,    0,    0,  132,    0,     0,  136,    0,     0,  140,    0,     0,
  35.   144,    0,    0,  144,    0,     0,  148,    0,     0,  152,    0,     0,
  36.   156,    0,    0,  160,    0,     0,  160,    0,     0,  164,    0,     0,
  37.   168,    0,    0,  172,    0,     0,  176,    0,     0,  180,    0,     0,
  38.   184,    4,    0,  188,    4,     0,  192,    8,     0,  196,    8,     0,
  39.   200,   12,    0,  204,   12,     0,  208,   16,     0,  212,   16,     0,
  40.   216,   20,    0,  220,   20,     0,  224,   24,     0,  228,   24,     0,
  41.   232,   28,    0,  236,   28,     0,  240,   32,     0,  244,   32,     0,
  42.   252,   36,    0,  252,   36,     0,  252,   40,     0,  252,   40,     0,
  43.   252,   44,    0,  252,   44,     0,  252,   48,     0,  252,   48,     0,
  44.   252,   52,    0,  252,   52,     0,  252,   56,     0,  252,   56,     0,
  45.   252,   60,    0,  252,   60,     0,  252,   64,     0,  252,   64,     0,
  46.   252,   68,    0,  252,   68,     0,  252,   72,     0,  252,   72,     0,
  47.   252,   76,    0,  252,   76,     0,  252,   80,     0,  252,   80,     0,
  48.   252,   84,    0,  252,   84,     0,  252,   88,     0,  252,   88,     0,
  49.   252,   92,    0,  252,   96,     0,  252,   96,     0,  252,  100,     0,
  50.   252,  100,    0,  252,  104,     0,  252,  104,     0,  252,  108,     0,
  51.   252,  108,    0,  252,  112,     0,  252,  112,     0,  252,  116,     0,
  52.   252,  116,    0,  252,  120,     0,  252,  120,     0,  252,  124,     0,
  53.   252,  124,    0,  252,  128,     0,  252,  128,     0,  252,  132,     0,
  54.   252,  132,    0,  252,  136,     0,  252,  136,     0,  252,  140,     0,
  55.   252,  140,    0,  252,  144,     0,  252,  144,     0,  252,  148,     0,
  56.   252,  152,    0,  252,  152,     0,  252,  156,     0,  252,  156,     0,
  57.   252,  160,    0,  252,  160,     0,  252,  164,     0,  252,  164,     0,
  58.   252,  168,    0,  252,  168,     0,  252,  172,     0,  252,  172,     0,
  59.   252,  176,    0,  252,  176,     0,  252,  180,     0,  252,  180,     0,
  60.   252,  184,    0,  252,  184,     0,  252,  188,     0,  252,  188,     0,
  61.   252,  192,    0,  252,  192,     0,  252,  196,     0,  252,  196,     0,
  62.   252,  200,    0,  252,  200,     0,  252,  204,     0,  252,  208,     0,
  63.   252,  208,    0,  252,  208,     0,  252,  208,     0,  252,  208,     0,
  64.   252,  212,    0,  252,  212,     0,  252,  212,     0,  252,  212,     0,
  65.   252,  216,    0,  252,  216,     0,  252,  216,     0,  252,  216,     0,
  66.   252,  216,    0,  252,  220,     0,  252,  220,     0,  252,  220,     0,
  67.   252,  220,    0,  252,  224,     0,  252,  224,     0,  252,  224,     0,
  68.   252,  224,    0,  252,  228,     0,  252,  228,     0,  252,  228,     0,
  69.   252,  228,    0,  252,  228,     0,  252,  232,     0,  252,  232,     0,
  70.   252,  232,    0,  252,  232,     0,  252,  236,     0,  252,  236,     0,
  71.   252,  236,    0,  252,  236,     0,  252,  240,     0,  252,  240,     0,
  72.   252,  244,    0,  252,  244,     0,  252,  244,     0,  252,  248,     0,
  73.   252,  248,    0,  252,  248,     0,  252,  248,     0,  252,  252,     0,
  74.   252,  252,    4,  252,  252,     8,  252,  252,    12,  252,  252,    16,
  75.   252,  252,   20,  252,  252,    24,  252,  252,    28,  252,  252,    32,
  76.   252,  252,   36,  252,  252,    40,  252,  252,    40,  252,  252,    44,
  77.   252,  252,   48,  252,  252,    52,  252,  252,    56,  252,  252,    60,
  78.   252,  252,   64,  252,  252,    68,  252,  252,    72,  252,  252,    76,
  79.   252,  252,   80,  252,  252,    84,  252,  252,    84,  252,  252,    88,
  80.   252,  252,   92,  252,  252,    96,  252,  252,   100,  252,  252,   104,
  81.   252,  252,  108,  252,  252,   112,  252,  252,   116,  252,  252,   120,
  82.   252,  252,  124,  252,  252,   124,  252,  252,   128,  252,  252,   132,
  83.   252,  252,  136,  252,  252,   140,  252,  252,   144,  252,  252,   148,
  84.   252,  252,  152,  252,  252,   156,  252,  252,   160,  252,  252,   164,
  85.   252,  252,  168,  252,  252,   168,  252,  252,   172,  252,  252,   176,
  86.   252,  252,  180,  252,  252,   184,  252,  252,   188,  252,  252,   192,
  87.   252,  252,  196,  252,  252,   200,  252,  252,   204,  252,  252,   208,
  88.   252,  252,  208,  252,  252,   212,  252,  252,   216,  252,  252,   220,
  89.   252,  252,  224,  252,  252,   228,  252,  252,   232,  252,  252,   236,
  90.   252,  252,  240,  252,  252,   244,  252,  252,   248,  252,  252,   252,
  91.   252,  252,  240,  252,  252,   244,  252,  252,   248,  252,  252,   252);
  92.  
  93.    radius    = 1.9;
  94.    frequency = 20;
  95.    angleinc  = 50 * pi / frequency;
  96. var
  97.    count       : word;
  98.    delta       : integer;
  99.    path        : array[0..199] of word;
  100.    buffer      : array[0..102,0..159] of integer;
  101.  
  102. procedure buildpath;
  103.    var
  104.       count     : byte;
  105.       currangle : real;
  106.    begin
  107.       currangle := pi;
  108.       for count := 0 to 199 do
  109.          begin
  110.             path[count] := 320 + round(radius*sin(currangle));
  111.  
  112.             { the sin path _must_ lie on an even number }
  113.             { otherwise the picture will be garbage     }
  114.  
  115.             if path[count] mod 2 <> 0 then
  116.                if path[count] > 320 then
  117.                   dec(path[count])            { round down }
  118.                else
  119.                   inc(path[count]);           { round up   }
  120.  
  121.             { the path is rounded to the closest even number to 320 }
  122.  
  123.             currangle := currangle + angleinc;
  124.          end;
  125.    end;
  126.  
  127. begin
  128.   randomize;
  129.   buildpath;
  130.  
  131.   asm
  132.      mov   ax,13h              { ; AX := 13h                            }
  133.      int   10h                 { ; Set Mode 13h (320x200x256)           }
  134.  
  135.      xor   ax,ax               { ; AX := 0                              }
  136.      mov   cx,768              { ; CX := # of palette entries           }
  137.      mov   dx,03C8h            { ; DX := VGA Port                       }
  138.      mov   si,offset palette   { ; SI := palette[0]                     }
  139.  
  140.      out   dx,al               { ; send zero to index port              }
  141.      inc   dx                  { ; inc to write port                    }
  142.  
  143.    @l1:
  144.  
  145.      mov   bl,[si]             { ; set palette entry                    }
  146.      shr   bl,2                { ; divide by 4                          }
  147.      mov   [si],bl             { ; save entry                           }
  148.      outsb                     { ; and write to port                    }
  149.      dec   cx                  { ; CX := CX - 1                         }
  150.      jnz   @l1                 { ; if not done then loop                }
  151.  
  152.      mov   ax,seg buffer       { ; AX := segment of buffer              }
  153.      mov   es,ax               { ; ES := AX                             }
  154.      mov   di,offset buffer    { ; DI := buffer[0]                      }
  155.      mov   cx,8109             { ; CX := sizeof(buffer) div 2           }
  156.      xor   ax,ax               { ; AX := 0                              }
  157.      rep   stosw               { ; clear every element in buffer to zero}
  158.   end;
  159.  
  160.   repeat
  161.  
  162.      asm
  163.         mov   bx,1             { ; BX := 1                              }
  164.         mov   si,offset path   { ; SI := path[0]                        }
  165.  
  166.         mov   cx,16160         { ; CX := # of elements to change        }
  167.         mov   di,offset buffer { ; DI := buffer[0]                      }
  168.         add   di,320           { ; DI := buffer[320] (0,1)              }
  169.  
  170.      @l2:
  171.  
  172.         mov   ax,ds:[di-2]     { ; AX := buffer[DI-2]    (x-1,y)        }
  173.         add   ax,ds:[di]       { ; AX += buffer[DI]      (x  ,y)        }
  174.         add   ax,ds:[di+2]     { ; AX += buffer[DI+2]    (x+1,y)        }
  175.         add   ax,ds:[di+320]   { ; AX += buffer[DI+320]  (x,y+1)        }
  176.         shr   ax,2             { ; AX := AX div 4 (calc average)        }
  177.  
  178.         jz    @l3              { ; if AX = 0 then skip next line        }
  179.         dec   ax               { ; else AX--                            }
  180.  
  181.      @l3:
  182.  
  183.         push  di               { ; save DI                              }
  184.         sub   di,ds:[si]       { ; DI := (x + or - sin,y-1)             }
  185.         mov   word ptr ds:[di],ax { store AX somewhere one line up      }
  186.         pop   di               { ; restore DI                           }
  187.  
  188.         inc   di               { ; DI++                                 }
  189.         inc   di               { ; DI++ (move to next word)             }
  190.  
  191.         inc   bx               { ; BX++                                 }
  192.         cmp   bx,320           { ; if bx <> 320                         }
  193.         jle   @l4              { ; then jump to @l4                     }
  194.         mov   bx,1             { ; else BX := 1 (we're on a new line)   }
  195.         inc   si               { ; point SI to next element in path     }
  196.         inc   si               { ;                                      }
  197.  
  198.      @l4:
  199.         dec   cx               { ; CX--                                 }
  200.         jnz   @l2              { ; if CX <> 0 then loop                 }
  201.      end;
  202.  
  203.      for count := 0 to 159 do {set new bottom line}
  204.         begin
  205.            if random < 0.4 then
  206.               delta := random(2)*255;
  207.            buffer[101,count] := delta;
  208.            buffer[102,count] := delta;
  209.         end;
  210.  
  211.      asm
  212.         mov   si,offset buffer { ; SI := buffer[0]                      }
  213.         mov   ax,0A000h        { ; AX := 0A000h (vga segment)           }
  214.         mov   es,ax            { ; ES := AX                             }
  215.         xor   di,di            { ; DI := 0                              }
  216.         mov   dx,100           { ; DX := 100 (# of rows div 2)          }
  217.  
  218.      @l5:
  219.         mov   bx,2             { ; BX := 2                              }
  220.  
  221.      @l6:
  222.         mov   cx,160           { ; CX := 160 (# of cols div 2)          }
  223.  
  224.      @l7:
  225.         mov   al,ds:[si]       { ; AL := buffer[si]                     }
  226.         mov   ah,al            { ; AH := AL (replicate byte)            }
  227.         mov   es:[di],ax       { ; store two bytes into video memory    }
  228.         inc   di               { ; move to next word in VRAM            }
  229.         inc   di               { ;                                      }
  230.         inc   si               { ; move to next word in buffer          }
  231.         inc   si               { ;                                      }
  232.         dec   cx               { ; CX--                                 }
  233.         jnz   @l7              { ; repeat until done with column        }
  234.  
  235.         sub   si,320           { ; go back to start of line in buffer   }
  236.         dec   bx               { ; BX--                                 }
  237.         jnz   @l6              { ; repeat until two columns filled      }
  238.  
  239.         add   si,320           { ; restore position in buffer           }
  240.         dec   dx               { ; DX--                                 }
  241.         jnz   @l5              { ; repeat until 100 rows filled         }
  242.      end;
  243.  
  244.   until keypressed;
  245.  
  246.   asm
  247.      mov   ax,03h              { ; AX := 3h                             }
  248.      int   10h                 { ; restore text mode                    }
  249.   end;
  250.  
  251. end.
  252.